import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client' import { TRANSACTIONS_PATH, ACCOUNTS_PATH } from '@urls' import { ChainInfo } from '@components/misc/ChainInfo' import { Error } from '@components/Error' import { StandardPageContainer } from '@components/layouts/StandardPageContainer' import { useRouter } from 'next/router' import { CHAINS } from '@synapsecns/synapse-constants' import { GET_BRIDGE_TRANSACTIONS_QUERY } from '@graphql/queries' import { API_URL } from '@graphql' import { HorizontalDivider } from '@components/misc/HorizontalDivider' import { formatDateTimestamp } from '@utils/formatDate' import { IconAndAmount } from '@components/misc/IconAndAmount' import { addressToSymbol } from '@utils/addressToSymbol' const CHAINS_BY_ID = CHAINS.CHAINS_BY_ID const link = new HttpLink({ uri: API_URL, useGETForQueries: true, }) const client = new ApolloClient({ link, cache: new InMemoryCache(), }) const truncateAddress = (address) => { return `${address.slice(0, 6)}...${address.slice(-4)}` } const truncateHash = (hash) => { return `${hash.slice(0, 8)}...${hash.slice(-5)}` } export const BridgeTransaction = ({ queryResult }) => { const router = useRouter() const { kappa } = router.query const transaction = queryResult.bridgeTransactions[0] const { pending, fromInfo, toInfo } = transaction // Get time taken to complete tx w/ appropriate units. const getTimeElapsedStr = (start, end) => { const diff = end - start if (diff <= 0) { return '1 second' } return diff === 1 ? '1 second' : `${diff} seconds` } let content if (!!transaction) { content = ( <>
← Explorer / { try { navigator.clipboard .writeText(String(kappa)) .then(() => '') .catch((err) => alert('Failed to copy text: ' + err)) } catch (err) { alert('Clipboard not supported on this browser') } }} > {kappa} {truncateAddress(kappa)}

Timestamp

{formatDateTimestamp(new Date(fromInfo.time * 1000))}

{new Date(fromInfo.time * 1000) .toISOString() .replace('T', ' ') .slice(0, 16) + ' UTC'}

Status

{pending ? 'Pending' : 'Confirmed'}{' '}

Elapsed

{toInfo ? getTimeElapsedStr(fromInfo.time, toInfo.time) : '--'}{' '}

Sent

on

Received

{toInfo ? (
on
) : (

--

)}

Txn Hash

{kappa} {truncateHash(kappa)}

From Txn

{fromInfo ? ( {fromInfo.hash} {truncateHash(fromInfo.hash)} ) : (

--

)}

Dest Txn

{toInfo ? ( {toInfo.hash} {truncateHash(toInfo.hash)} ) : (

--

)}

) } else { content = ( ) } return {content} } const TransactionPage = ({ queryResult }) => { return } export default TransactionPage export const getServerSideProps = async (context) => { const { data } = await client.query({ query: GET_BRIDGE_TRANSACTIONS_QUERY, variables: { chainId: context.params.chainIdFrom, kappa: context.params.kappa, useMv: true, }, }) return { props: { queryResult: data, }, // will be passed to the page component as props } }